package cn.afterturn.svn.analysis.task;

import java.util.List;

import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import cn.afterturn.svn.analysis.entity.historyinfo.HistoryInfoEntity;
import cn.afterturn.svn.analysis.entity.repositoryinfo.RepositoryInfoEntity;
import cn.afterturn.svn.analysis.service.historyinfo.HistoryInfoService;
import cn.afterturn.svn.analysis.service.repositoryinfo.RepositoryInfoService;
import cn.afterturn.svn.analysis.svn.SvnHistory;

/**
 * 读取提交记录的定时任务,读取类别,批量查询记录,插入记录
 * @author JueYue
 * @date 2015年7月29日 下午4:21:15
 */
@IocBean
public class HistoryTask implements Job {

    @Inject
    private RepositoryInfoService repositoryInfoService;

    @Inject
    private HistoryInfoService historyInfoService;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        List<RepositoryInfoEntity> repositoryList = repositoryInfoService.query(null, null);
        for (int i = 0; i < repositoryList.size(); i++) {
            loadSvnHisttory(repositoryList.get(i));
        }

    }

    /**
     * 加载文件历史
     * @param repositoryInfoEntity
     */
    private void loadSvnHisttory(RepositoryInfoEntity repositoryInfoEntity) {
        List<HistoryInfoEntity> list = SvnHistory.getHistory(repositoryInfoEntity);
        if (list != null && !list.isEmpty()) {
            historyInfoService.batchSaveHistoryInf(list);
        }
    }

}
